﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lg.Core.Form.Types
{
    public class Address : BaseType, IType
    {
        /// <summary>
        /// 地址格式化参数
        /// 省/市/区/详细地址 level=4
        /// 
        /// </summary>     
        public int Level { get; set; }

        /// <summary>
        /// 地址格式化参数
        /// 省/市/区/详细地址 level=4
        /// </summary>
        public int RequiredLevel { get; set; }

        public void GetSaveDbValue(Dictionary<string, dynamic> formData,string inputValue)
        {

            formData.Add(Name,inputValue);
        }

        public void Verify()
        {
            if (this.IsRender)
            {
                if (Required)
                {
                    Validate.Required(Value, $"字段:{Title},不可为空！");
                    if (Level > 0)
                    {
                        string[] arry = Value!.Split(" > ");
                        if (arry.Length != Level)
                        {
                            throw new Exception($"{Value} 地址信息请填写完整");
                        }
                    }
                }
            }
        }

    }
}
